import random


class Gesture:
    def __init__(self, name):
        self.name = name
        self.beats = None  # 定义击败的对象

    def __gt__(self, other):
        return self.beats.name == other.name

    def __eq__(self, other):
        return self.name == other.name

    def __str__(self):
        return self.name


# 初始化三个手势对象
rock = Gesture("石头")
scissors = Gesture("剪刀")
paper = Gesture("布")

# 设置胜负关系
rock.beats = scissors
scissors.beats = paper
paper.beats = rock

# 游戏字典
choices = {1: rock, 2: scissors, 3: paper}

while True:
    print("\n开始猜拳 -> 1: 石头，2: 剪刀，3: 布，4: 退出")
    try:
        choice = int(input("请选择："))
        if choice == 4:
            break
        if choice not in choices:
            print("请输入有效选项！")
            continue
        player = choices[choice]
        computer = random.choice(list(choices.values()))
        print(f"你出的是 {player}，电脑出的是 {computer}")
        if player > computer:
            print("你赢了！")
        elif computer > player:
            print("你输了！")
        else:
            print("平手！")
    except ValueError:
        print("请输入数字！")
